<template>
	<section v-loading="listLoading">
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.alipayAccount" placeholder="提现支付宝账号"></el-input>
				</el-form-item>
				<el-form-item>
					<el-input v-model="filters.realName" placeholder="真实姓名"></el-input>
				</el-form-item>
				<el-form-item label="状态">
                    <el-select v-model="filters.status" clearable> 
                        <el-option v-for="item in optionStatus" :key="item.value" :label="item.label" :value="item.value"></el-option>
                    </el-select>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" size="medium" v-on:click="handleCurrentChange(1)">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="users" stripe highlight-current-row @selection-change="selsChange" border style="width: 100%;">
			<el-table-column prop="id" label="ID" width="60" align="center">
			</el-table-column>
			<el-table-column prop="alipayAccount" label="提现支付宝账号" min-width="80" align="center">
			</el-table-column>
			<el-table-column prop="realName" label="支付宝姓名" min-width="90" align="center">
			</el-table-column>
			<el-table-column prop="money" label="金额" min-width="90" align="center">
			</el-table-column>
			<el-table-column prop="result" label="提现结果" min-width="80" align="center">
				<template slot-scope="scope">
					<span v-if="scope.row.status == 0">待审核</span>
					<span v-if="scope.row.status == 1">审核通过</span>
					<span v-if="scope.row.status == 2">{{scope.row.failReason}}</span>
				</template>
			</el-table-column>
			<el-table-column prop="status" label="提现状态" min-width="80" align="center">
				<template slot-scope="scope">
					<span v-if="scope.row.status == 0" style="font-weight: bold;">待审核</span>
					<span v-if="scope.row.status == 1" style="color: #00CC00;font-weight: bold;">审核通过</span>
					<span v-if="scope.row.status == 2" style="color: red;font-weight: bold;">审核拒绝</span>
				</template>
			</el-table-column>
			<el-table-column prop="auditTime" label="审核时间" min-width="100" align="center">
				<template slot-scope="scope">
					<span v-if="scope.row.auditTime !== null && scope.row.auditTime !== undefined && scope.row.auditTime !== ''">{{timestampFormat(scope.row.auditTime)}}</span>
					<span v-else>/</span>
				</template>
			</el-table-column>
			<el-table-column prop="createTime" label="申请时间" :formatter="formatDate" min-width="100" align="center">
			</el-table-column>
			<el-table-column label="操作" width="150" align="center">
				<template slot-scope="scope">
					<el-button size="mini" plain :disabled="scope.row.status === 0 ? false : true" @click="through(scope.row.id)" type="success">通过</el-button>
					<el-button type="info" plain :disabled="scope.row.status === 0 ? false : true" size="mini" @click="Notthrough(scope.$index, scope.row)">拒绝</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<!--<el-button size="small" type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>-->
			<el-pagination background layout="prev, pager, next, jumper" @current-change="handleCurrentChange" :page-size="pageSize" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
        <el-dialog title="审核" :visible.sync="editFormVisible" :close-on-click-modal="false" width="500px">
			<el-form :model="editForm" label-width="80px" ref="editForm">
				<el-form-item label="理由" prop="failReason" :rules="[{ required: true, message: '请填写拒绝理由', trigger: 'blur' }]">
					<el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" v-model="editForm.failReason" auto-complete="off"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button size="mini" @click.native="editFormVisible = false">取消</el-button>
				<el-button size="mini" type="primary" @click.native="editSubmit">提交</el-button>
			</div>
		</el-dialog>
	</section>
</template>

<script>
	import { client } from '../../common/js/alioss'
	import util from '../../common/js/util'

	export default {
		data() {
			return {
				filters: {
					alipayAccount:'',
					realName: '',
					status:''
				},
				optionStatus:[{
					value:'',
					label:'全部'
				},{
					value:'0',
					label:'待审核'
				},{
					value:'1',
					label:'审核通过'
				},{
					value:'2',
					label:'审核拒绝'
				}],
				users: [],
				sels: [],
				total: 0,
				page: 1,
				pageSize: 10,
				listLoading: false,
				editFormVisible: false,
				editLoading: false,
                editForm: {
					failReason: '',
					id: '',
					status: 2,
				}
			}
		},
		
		methods: {
			zeroize(num) {
                return (String(num).length == 1 ? "0" : "") + num;
            },
            timestampFormat(timestamp) {
                var curTimestamp = parseInt(new Date().getTime() / 1000); //当前时间戳
                var timestampDiff = curTimestamp - parseInt(timestamp / 1000); // 参数时间戳与当前时间戳相差秒数
                var curDate = new Date(curTimestamp * 1000); // 当前时间日期对象
                var tmDate = new Date(parseInt(timestamp / 1000) * 1000); // 参数时间戳转换成的日期对象
                var Y = tmDate.getFullYear(),
                m = tmDate.getMonth() + 1,
                d = tmDate.getDate();
                var H = tmDate.getHours(),
                i = tmDate.getMinutes(),
                s = tmDate.getSeconds();
                return (Y + "-" + this.zeroize(m) + "-" + this.zeroize(d) + " " + this.zeroize(H) + ":" + this.zeroize(i) + ":" + this.zeroize(s));
            },
			//时间转换开始时间 
			formatDate(row, column) {
                let date = new Date(parseInt(row.createTime));
                let Y = date.getFullYear() + '-';
                let M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) + '-' : date.getMonth() + 1 + '-';
                let D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
                let h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
                let m = date.getMinutes()  < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
                let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
                return Y + M + D + h + m + s;
            },
			handleCurrentChange(val) {
				this.page = val;
				this.getUsers();
			},
			//获取用户列表
			getUsers:function (){
				this.listLoading = true;
				let para = {
					page: this.page,
					size: this.pageSize,
					alipayAccount: this.filters.alipayAccount,
					realName: this.filters.realName,
					status: this.filters.status,
				};
				var instance = this.$http.create({headers: {'content-type': 'application/x-www-form-urlencoded','sys-for-job-token':JSON.parse(sessionStorage.getItem('token'))},
				});  
				instance.post('sys/api/promote/manage/getWithdrawalList/v1_0_0', this.qs.stringify(para)).then(data => {
					let  res = data.data;
					console.log(data);
					if (res.code !== 200) {
						this.$message({
							message: res.msg,
							type: 'error'
						});
					} else {
						this.total = res.total;
						this.users = res.rows;
						this.listLoading = false;
					}
				});
			},
			
			selsChange: function (sels) {
				this.sels = sels;
			},
			//批量删除
			batchRemove: function () {
				var ids = this.sels.map(item => item.id).toString();
				this.handleDel(ids);
			},
			//通过
			through(id) {
				this.$confirm('确认通过审核吗?', '提示', {}).then(() => {
					this.listLoading = true;
					var instance = this.$http.create({headers: {'content-type': 'application/x-www-form-urlencoded','sys-for-job-token':JSON.parse(sessionStorage.getItem('token'))},
					});  
					instance.post('sys/api/promote/manage/auditWithdrawa/v1_0_0', this.qs.stringify({id: id,status: 1})).then(data => {
						let  res = data.data;
						if (res.code !== 200) {
							this.$message({
								message: res.msg,
								type: 'error'
							});
						} else {
							this.$message({
								message: '通过审核',
								type: 'success'
							});
							this.getUsers();
						}
					})
				}).catch(() => {
					
				});
			},
			//显示拒绝界面
			Notthrough: function (index, row) {
				this.editFormVisible = true;
				this.editForm.id = row.id;
			},
			//拒绝
			editSubmit: function () {
				this.$refs.editForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认拒绝吗？', '提示', {}).then(() => {
							this.editLoading = true;
							var instance = this.$http.create({headers: {'content-type': 'application/x-www-form-urlencoded','sys-for-job-token':JSON.parse(sessionStorage.getItem('token'))},
							});  
							instance.post('sys/api/promote/manage/auditWithdrawa/v1_0_0', this.qs.stringify(this.editForm)).then(data => {
								let  res = data.data;
								if (res.code !== 200) {
									this.$message({
										message: res.msg,
										type: 'error'
									});
								} else {
									this.editLoading = false;
									this.$message({
										message: '提交成功',
										type: 'success'
									});
									this.$refs['editForm'].resetFields();
									this.editFormVisible = false;
									this.getUsers();
								}
							});
						});
					}
				});
			},
		},
		mounted() {
			//this.getUsers();
		}
	}

</script>
<style>
</style>
